package com.space.service.impl;

import com.space.dao.CityDao;
import com.space.dao.FlightDao;
import com.space.entity.City;
import com.space.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * @author : 港某
 * @date : 2020/2/13 18:06
 */
@Service
public class CityServiceImpl implements CityService {

    @Autowired
    CityDao cityDao;
    @Autowired
    FlightDao flightDao;

    @Override
    public List<City> selectAllCity() {
        return cityDao.selectAllCity();
    }

    @Override
    public City selectCityById(int cityId) {
        return cityDao.selectCityById(cityId);
    }

    @Override
    public List<City> selectHotCity() {
        List<City> cityList = new LinkedList<City>();
        List<Integer> hotCityIdList = flightDao.selectSomeFlightByHot();

        for (int i = 0; i < hotCityIdList.size(); i++) {
            cityList.add(cityDao.selectCityById(hotCityIdList.get(i).intValue()));
        }
        return cityList;
    }
}
